#ifndef MOT_HALSTRUCT_H
#define MOT_HALSTRUCT_H
#include "../../hal/hal.h"
#include "config.h"
#include "zuc/nml_intf/zucpos.h"
#include "zucmotcfg.h"

typedef struct
{
    float coarse_pos_cmd;   /* RPI: commanded position, w/o comp */
    float joint_vel_cmd;    /* RPI: commanded velocity, w/o comp */
    float backlash_corr;    /* RPI: correction for backlash */
    float backlash_filt;    /* RPI: filtered backlash correction */
    float backlash_vel;     /* RPI: backlash speed variable */
    float motor_pos_cmd;    /* WPI: commanded position, with comp */
    float motor_pos_fb;     /* RPI: position feedback, with comp */
                            // float *motor_velocity_cmd;    /* command velocity of the joint move   */
                            // float *motor_acceleration_cmd;    /* command acceleration of the joint move   */
    int32_t abs_pos_fb;     /* RPI: encoder position feedback, with comp, for drag mode */
    int32_t motor_curr_cmd; /*WPI: commanded current, with comp, for Drag mode*/
    float joint_pos_cmd;    /* WPI: commanded position w/o comp, mot ofs */
    float joint_pos_fb;     /* RPI: position feedback, w/o comp */
    float f_error;          /* RPI: following error */
    float f_error_lim;      /* RPI: following error limit */

    float free_pos_cmd;     /* RPI: free traj planner pos cmd */
    float free_vel_lim;     /* RPI: free traj planner vel limit */
    bool free_tp_enable;    /* RPI: free traj planner is running */
    bool kb_jjog_active;    /* RPI: executing keyboard jog */
    bool wheel_jjog_active; /* RPI: executing handwheel jog */

    bool active;        /* RPI: joint is active, whatever that means */
    bool in_position;   /* RPI: joint is in position */
    bool error;         /* RPI: joint has an error */
    bool phl;           /* RPI: joint is at positive hard limit */
    bool nhl;           /* RPI: joint is at negative hard limit */
    bool homing;        /* RPI: joint is homing */
    bool homed;         /* RPI: joint was homed */
    bool f_errored;     /* RPI: joint had too much following error */
    bool faulted;       /* RPI: joint amp faulted */
    bool pos_lim_sw;    /* RPI: positive limit switch input */
    bool neg_lim_sw;    /* RPI: negative limit switch input */
    bool home_sw;       /* RPI: home switch input */
    bool index_enable;  /* RPIO: zucmotmod sets: request reset on index
				         encoder clears: index arrived */
    bool amp_fault;     /* RPI: amp fault input */
    bool amp_enable;    /* WPI: amp enable output */
    int32_t home_state; /* WPI: homing state machine state */

    bool unlock;      /* WPI: command that axis should unlock for rotation */
    bool is_unlocked; /* RPI: axis is currently unlocked */

    int32_t jjog_counts; /* WPI: jogwheel position input */
    bool jjog_enable;    /* RPI: enable jogwheel */
    float jjog_scale;    /* RPI: distance to jog on each count */
    bool jjog_vel_mode;  /* RPI: true for "velocity mode" jogwheel */

} joint_hal_t;

typedef struct
{
    float pos_cmd;         /* RPI: commanded position */
    float teleop_vel_cmd;  /* RPI: commanded velocity */
    float teleop_pos_cmd;  /* RPI: teleop traj planner pos cmd */
    float teleop_vel_lim;  /* RPI: teleop traj planner vel limit */
    bool teleop_tp_enable; /* RPI: teleop traj planner is running */

    float teleop_tool_vel_cmd;  /* RPI: commanded velocity */
    float teleop_tool_pos_cmd;  /* RPI: teleop traj planner pos cmd */
    float teleop_tool_vel_lim;  /* RPI: teleop traj planner vel limit */
    bool teleop_tool_tp_enable; /* RPI: teleop traj planner is running */

    int32_t ajog_counts;    /* WPI: jogwheel position input */
    bool ajog_enable;       /* RPI: enable jogwheel */
    float ajog_scale;       /* RPI: distance to jog on each count */
    bool ajog_vel_mode;     /* RPI: true for "velocity mode" jogwheel */
    bool kb_ajog_active;    /* RPI: executing keyboard jog */
    bool wheel_ajog_active; /* RPI: executing handwheel jog */
} axis_hal_t;

typedef enum
{
    ZUC_MBHLDING_GEN_0 = 100,  //
    ZUC_MBHLDING_GEN_1,
    ZUC_MBHLDING_GEN_2,
    ZUC_MBHLDING_GEN_3,
    ZUC_MBHLDING_GEN_4,
    ZUC_MBHLDING_GEN_5,
    ZUC_MBHLDING_GEN_6,
    ZUC_MBHLDING_GEN_7,
    ZUC_MBHLDING_GEN_8,
    ZUC_MBHLDING_GEN_9,
    ZUC_MBHLDING_GEN_10,
    ZUC_MBHLDING_GEN_11,
    ZUC_MBHLDING_GEN_12,
    ZUC_MBHLDING_GEN_13,
    ZUC_MBHLDING_GEN_14,
    ZUC_MBHLDING_GEN_15,
    ZUC_MBHLDING_GEN_SIGNED_0,
    ZUC_MBHLDING_GEN_SIGNED_1,
    ZUC_MBHLDING_GEN_SIGNED_2,
    ZUC_MBHLDING_GEN_SIGNED_3,
    ZUC_MBHLDING_GEN_SIGNED_4,
    ZUC_MBHLDING_GEN_SIGNED_5,
    ZUC_MBHLDING_GEN_SIGNED_6,
    ZUC_MBHLDING_GEN_SIGNED_7,
    ZUC_MBHLDING_GEN_SIGNED_8,
    ZUC_MBHLDING_GEN_SIGNED_9,
    ZUC_MBHLDING_GEN_SIGNED_10,
    ZUC_MBHLDING_GEN_SIGNED_11,
    ZUC_MBHLDING_GEN_SIGNED_12,
    ZUC_MBHLDING_GEN_SIGNED_13,
    ZUC_MBHLDING_GEN_SIGNED_14,
    ZUC_MBHLDING_GEN_SIGNED_15,
    ZUC_MBHLDING_FLOAT_0_H,
    ZUC_MBHLDING_FLOAT_0_L,
    ZUC_MBHLDING_FLOAT_1_H,
    ZUC_MBHLDING_FLOAT_1_L,
    ZUC_MBHLDING_FLOAT_2_H,
    ZUC_MBHLDING_FLOAT_2_L,
    ZUC_MBHLDING_FLOAT_3_H,
    ZUC_MBHLDING_FLOAT_3_L,
    ZUC_MBHLDING_FLOAT_4_H,
    ZUC_MBHLDING_FLOAT_4_L,
    ZUC_MBHLDING_FLOAT_5_H,
    ZUC_MBHLDING_FLOAT_5_L,
    ZUC_MBHLDING_FLOAT_6_H,
    ZUC_MBHLDING_FLOAT_6_L,
    ZUC_MBHLDING_FLOAT_7_H,
    ZUC_MBHLDING_FLOAT_7_L,
    ZUC_MBHLDING_FLOAT_8_H,
    ZUC_MBHLDING_FLOAT_8_L,
    ZUC_MBHLDING_FLOAT_9_H,
    ZUC_MBHLDING_FLOAT_9_L,
    ZUC_MBHLDING_FLOAT_10_H,
    ZUC_MBHLDING_FLOAT_10_L,
    ZUC_MBHLDING_FLOAT_11_H,
    ZUC_MBHLDING_FLOAT_11_L,
    ZUC_MBHLDING_FLOAT_12_H,
    ZUC_MBHLDING_FLOAT_12_L,
    ZUC_MBHLDING_FLOAT_13_H,
    ZUC_MBHLDING_FLOAT_13_L,
    ZUC_MBHLDING_FLOAT_14_H,
    ZUC_MBHLDING_FLOAT_14_L,
    ZUC_MBHLDING_FLOAT_15_H,
    ZUC_MBHLDING_FLOAT_15_L,
    ZUC_MBHLDING_FLOAT_16_H,
    ZUC_MBHLDING_FLOAT_16_L,
    ZUC_MBHLDING_FLOAT_17_H,
    ZUC_MBHLDING_FLOAT_17_L,
    ZUC_MBHLDING_FLOAT_18_H,
    ZUC_MBHLDING_FLOAT_18_L,
    ZUC_MBHLDING_FLOAT_19_H,
    ZUC_MBHLDING_FLOAT_19_L,
    ZUC_MBHLDING_FLOAT_20_H,
    ZUC_MBHLDING_FLOAT_20_L,
    ZUC_MBHLDING_FLOAT_21_H,
    ZUC_MBHLDING_FLOAT_21_L,
    ZUC_MBHLDING_FLOAT_22_H,
    ZUC_MBHLDING_FLOAT_22_L,
    ZUC_MBHLDING_FLOAT_23_H,
    ZUC_MBHLDING_FLOAT_23_L,
    ZUC_MBHLDING_FLOAT_24_H,
    ZUC_MBHLDING_FLOAT_24_L,
    ZUC_MBHLDING_FLOAT_25_H,
    ZUC_MBHLDING_FLOAT_25_L,
    ZUC_MBHLDING_FLOAT_26_H,
    ZUC_MBHLDING_FLOAT_26_L,
    ZUC_MBHLDING_FLOAT_27_H,
    ZUC_MBHLDING_FLOAT_27_L,
    ZUC_MBHLDING_FLOAT_28_H,
    ZUC_MBHLDING_FLOAT_28_L,
    ZUC_MBHLDING_FLOAT_29_H,
    ZUC_MBHLDING_FLOAT_29_L,
    ZUC_MBHLDING_FLOAT_30_H,
    ZUC_MBHLDING_FLOAT_30_L,
    ZUC_MBHLDING_FLOAT_31_H,
    ZUC_MBHLDING_FLOAT_31_L,
    ZUC_MBHLDING_ALL
} zuc_mb_holding_reg_idx_t;

typedef enum
{
    ZUC_MB_INREG_GEN_0 = 96,
    ZUC_MB_INREG_GEN_1,
    ZUC_MB_INREG_GEN_2,
    ZUC_MB_INREG_GEN_3,
    ZUC_MB_INREG_GEN_4,
    ZUC_MB_INREG_GEN_5,
    ZUC_MB_INREG_GEN_6,
    ZUC_MB_INREG_GEN_7,
    ZUC_MB_INREG_GEN_8,
    ZUC_MB_INREG_GEN_9,
    ZUC_MB_INREG_GEN_10,
    ZUC_MB_INREG_GEN_11,
    ZUC_MB_INREG_GEN_12,
    ZUC_MB_INREG_GEN_13,
    ZUC_MB_INREG_GEN_14,
    ZUC_MB_INREG_GEN_15,
    ZUC_MB_INREG_GEN_SIGNED_0,
    ZUC_MB_INREG_GEN_SIGNED_1,
    ZUC_MB_INREG_GEN_SIGNED_2,
    ZUC_MB_INREG_GEN_SIGNED_3,
    ZUC_MB_INREG_GEN_SIGNED_4,
    ZUC_MB_INREG_GEN_SIGNED_5,
    ZUC_MB_INREG_GEN_SIGNED_6,
    ZUC_MB_INREG_GEN_SIGNED_7,
    ZUC_MB_INREG_GEN_SIGNED_8,
    ZUC_MB_INREG_GEN_SIGNED_9,
    ZUC_MB_INREG_GEN_SIGNED_10,
    ZUC_MB_INREG_GEN_SIGNED_11,
    ZUC_MB_INREG_GEN_SIGNED_12,
    ZUC_MB_INREG_GEN_SIGNED_13,
    ZUC_MB_INREG_GEN_SIGNED_14,
    ZUC_MB_INREG_GEN_SIGNED_15,

    ZUC_MB_INREG_GEN_FLOAT_0_H,
    ZUC_MB_INREG_GEN_FLOAT_0_L,
    ZUC_MB_INREG_GEN_FLOAT_1_H,
    ZUC_MB_INREG_GEN_FLOAT_1_L,
    ZUC_MB_INREG_GEN_FLOAT_2_H,
    ZUC_MB_INREG_GEN_FLOAT_2_L,
    ZUC_MB_INREG_GEN_FLOAT_3_H,
    ZUC_MB_INREG_GEN_FLOAT_3_L,
    ZUC_MB_INREG_GEN_FLOAT_4_H,
    ZUC_MB_INREG_GEN_FLOAT_4_L,
    ZUC_MB_INREG_GEN_FLOAT_5_H,
    ZUC_MB_INREG_GEN_FLOAT_5_L,
    ZUC_MB_INREG_GEN_FLOAT_6_H,
    ZUC_MB_INREG_GEN_FLOAT_6_L,
    ZUC_MB_INREG_GEN_FLOAT_7_H,
    ZUC_MB_INREG_GEN_FLOAT_7_L,
    ZUC_MB_INREG_GEN_FLOAT_8_H,
    ZUC_MB_INREG_GEN_FLOAT_8_L,
    ZUC_MB_INREG_GEN_FLOAT_9_H,
    ZUC_MB_INREG_GEN_FLOAT_9_L,
    ZUC_MB_INREG_GEN_FLOAT_10_H,
    ZUC_MB_INREG_GEN_FLOAT_10_L,
    ZUC_MB_INREG_GEN_FLOAT_11_H,
    ZUC_MB_INREG_GEN_FLOAT_11_L,
    ZUC_MB_INREG_GEN_FLOAT_12_H,
    ZUC_MB_INREG_GEN_FLOAT_12_L,
    ZUC_MB_INREG_GEN_FLOAT_13_H,
    ZUC_MB_INREG_GEN_FLOAT_13_L,
    ZUC_MB_INREG_GEN_FLOAT_14_H,
    ZUC_MB_INREG_GEN_FLOAT_14_L,
    ZUC_MB_INREG_GEN_FLOAT_15_H,
    ZUC_MB_INREG_GEN_FLOAT_15_L,
    ZUC_MB_INREG_GEN_FLOAT_16_H,
    ZUC_MB_INREG_GEN_FLOAT_16_L,
    ZUC_MB_INREG_GEN_FLOAT_17_H,
    ZUC_MB_INREG_GEN_FLOAT_17_L,
    ZUC_MB_INREG_GEN_FLOAT_18_H,
    ZUC_MB_INREG_GEN_FLOAT_18_L,
    ZUC_MB_INREG_GEN_FLOAT_19_H,
    ZUC_MB_INREG_GEN_FLOAT_19_L,
    ZUC_MB_INREG_GEN_FLOAT_20_H,
    ZUC_MB_INREG_GEN_FLOAT_20_L,
    ZUC_MB_INREG_GEN_FLOAT_21_H,
    ZUC_MB_INREG_GEN_FLOAT_21_L,
    ZUC_MB_INREG_GEN_FLOAT_22_H,
    ZUC_MB_INREG_GEN_FLOAT_22_L,
    ZUC_MB_INREG_GEN_FLOAT_23_H,
    ZUC_MB_INREG_GEN_FLOAT_23_L,
    ZUC_MB_INREG_GEN_FLOAT_24_H,
    ZUC_MB_INREG_GEN_FLOAT_24_L,
    ZUC_MB_INREG_GEN_FLOAT_25_H,
    ZUC_MB_INREG_GEN_FLOAT_25_L,
    ZUC_MB_INREG_GEN_FLOAT_26_H,
    ZUC_MB_INREG_GEN_FLOAT_26_L,
    ZUC_MB_INREG_GEN_FLOAT_27_H,
    ZUC_MB_INREG_GEN_FLOAT_27_L,
    ZUC_MB_INREG_GEN_FLOAT_28_H,
    ZUC_MB_INREG_GEN_FLOAT_28_L,
    ZUC_MB_INREG_GEN_FLOAT_29_H,
    ZUC_MB_INREG_GEN_FLOAT_29_L,
    ZUC_MB_INREG_GEN_FLOAT_30_H,
    ZUC_MB_INREG_GEN_FLOAT_30_L,
    ZUC_MB_INREG_GEN_FLOAT_31_H,
    ZUC_MB_INREG_GEN_FLOAT_31_L,

    ZUC_MB_INREG_JNT_SPD_1_H,
    ZUC_MB_INREG_JNT_SPD_1_L,
    ZUC_MB_INREG_JNT_SPD_2_H,
    ZUC_MB_INREG_JNT_SPD_2_L,
    ZUC_MB_INREG_JNT_SPD_3_H,
    ZUC_MB_INREG_JNT_SPD_3_L,
    ZUC_MB_INREG_JNT_SPD_4_H,
    ZUC_MB_INREG_JNT_SPD_4_L,
    ZUC_MB_INREG_JNT_SPD_5_H,
    ZUC_MB_INREG_JNT_SPD_5_L,
    ZUC_MB_INREG_JNT_SN_1_H,
    ZUC_MB_INREG_JNT_SN_1_L,
    ZUC_MB_INREG_JNT_SN_2_H,
    ZUC_MB_INREG_JNT_SN_2_L,
    ZUC_MB_INREG_JNT_SN_3_H,
    ZUC_MB_INREG_JNT_SN_3_L,
    ZUC_MB_INREG_JNT_SN_4_H,
    ZUC_MB_INREG_JNT_SN_4_L,
    ZUC_MB_INREG_JNT_SN_5_H,
    ZUC_MB_INREG_JNT_SN_5_L,
    ZUC_MB_INREG_JNT_SN_6_H,
    ZUC_MB_INREG_JNT_SN_6_L,
    ZUC_MB_INREG_JNT_PWR_1_H,
    ZUC_MB_INREG_JNT_PWR_1_L,
    ZUC_MB_INREG_JNT_PWR_2_H,
    ZUC_MB_INREG_JNT_PWR_2_L,
    ZUC_MB_INREG_JNT_PWR_3_H,
    ZUC_MB_INREG_JNT_PWR_3_L,
    ZUC_MB_INREG_JNT_PWR_4_H,
    ZUC_MB_INREG_JNT_PWR_4_L,
    ZUC_MB_INREG_JNT_PWR_5_H,
    ZUC_MB_INREG_JNT_PWR_5_L,
    ZUC_MB_INREG_JNT_PWR_6_H,
    ZUC_MB_INREG_JNT_PWR_6_L,
    ZUC_MB_INREG_JNT_TMP_1_H,
    ZUC_MB_INREG_JNT_TMP_1_L,
    ZUC_MB_INREG_JNT_TMP_2_H,
    ZUC_MB_INREG_JNT_TMP_2_L,
    ZUC_MB_INREG_JNT_TMP_3_H,
    ZUC_MB_INREG_JNT_TMP_3_L,
    ZUC_MB_INREG_JNT_TMP_4_H,
    ZUC_MB_INREG_JNT_TMP_4_L,
    ZUC_MB_INREG_JNT_TMP_5_H,
    ZUC_MB_INREG_JNT_TMP_5_L,
    ZUC_MB_INREG_JNT_TMP_6_H,
    ZUC_MB_INREG_JNT_TMP_6_L,
    ZUC_MB_INREG_JNT_ANGL_1_H,
    ZUC_MB_INREG_JNT_ANGL_1_L,
    ZUC_MB_INREG_JNT_ANGL_2_H,
    ZUC_MB_INREG_JNT_ANGL_2_L,
    ZUC_MB_INREG_JNT_ANGL_3_H,
    ZUC_MB_INREG_JNT_ANGL_3_L,
    ZUC_MB_INREG_JNT_ANGL_4_H,
    ZUC_MB_INREG_JNT_ANGL_4_L,
    ZUC_MB_INREG_JNT_ANGL_5_H,
    ZUC_MB_INREG_JNT_ANGL_5_L,
    ZUC_MB_INREG_JNT_ANGL_6_H,
    ZUC_MB_INREG_JNT_ANGL_6_L,
    ZUC_MB_INREG_JNT_CRNT_1_H,
    ZUC_MB_INREG_JNT_CRNT_1_L,
    ZUC_MB_INREG_JNT_CRNT_2_H,
    ZUC_MB_INREG_JNT_CRNT_2_L,
    ZUC_MB_INREG_JNT_CRNT_3_H,
    ZUC_MB_INREG_JNT_CRNT_3_L,
    ZUC_MB_INREG_JNT_CRNT_4_H,
    ZUC_MB_INREG_JNT_CRNT_4_L,
    ZUC_MB_INREG_JNT_CRNT_5_H,
    ZUC_MB_INREG_JNT_CRNT_5_L,
    ZUC_MB_INREG_JNT_CRNT_6_H,
    ZUC_MB_INREG_JNT_CRNT_6_L,
    ZUC_MB_INREG_JNT_ERR_CODE_1_H,
    ZUC_MB_INREG_JNT_ERR_CODE_1_L,
    ZUC_MB_INREG_JNT_ERR_CODE_2_H,
    ZUC_MB_INREG_JNT_ERR_CODE_2_L,
    ZUC_MB_INREG_JNT_ERR_CODE_3_H,
    ZUC_MB_INREG_JNT_ERR_CODE_3_L,
    ZUC_MB_INREG_JNT_ERR_CODE_4_H,
    ZUC_MB_INREG_JNT_ERR_CODE_4_L,
    ZUC_MB_INREG_JNT_ERR_CODE_5_H,
    ZUC_MB_INREG_JNT_ERR_CODE_5_L,
    ZUC_MB_INREG_JNT_ERR_CODE_6_H,
    ZUC_MB_INREG_JNT_ERR_CODE_6_L,
    ZUC_MB_INREG_JNT_ERR_STS_1_H,
    ZUC_MB_INREG_JNT_ERR_STS_1_L,
    ZUC_MB_INREG_JNT_ERR_STS_2_H,
    ZUC_MB_INREG_JNT_ERR_STS_2_L,
    ZUC_MB_INREG_JNT_ERR_STS_3_H,
    ZUC_MB_INREG_JNT_ERR_STS_3_L,
    ZUC_MB_INREG_JNT_ERR_STS_4_H,
    ZUC_MB_INREG_JNT_ERR_STS_4_L,
    ZUC_MB_INREG_JNT_ERR_STS_5_H,
    ZUC_MB_INREG_JNT_ERR_STS_5_L,
    ZUC_MB_INREG_JNT_ERR_STS_6_H,
    ZUC_MB_INREG_JNT_ERR_STS_6_L,
    ZUC_MB_INREG_JNT_EN_STS_1_H,
    ZUC_MB_INREG_JNT_EN_STS_1_L,
    ZUC_MB_INREG_JNT_EN_STS_2_H,
    ZUC_MB_INREG_JNT_EN_STS_2_L,
    ZUC_MB_INREG_JNT_EN_STS_3_H,
    ZUC_MB_INREG_JNT_EN_STS_3_L,
    ZUC_MB_INREG_JNT_EN_STS_4_H,
    ZUC_MB_INREG_JNT_EN_STS_4_L,
    ZUC_MB_INREG_JNT_EN_STS_5_H,
    ZUC_MB_INREG_JNT_EN_STS_5_L,
    ZUC_MB_INREG_JNT_EN_STS_6_H,
    ZUC_MB_INREG_JNT_EN_STS_6_L,
    ZUC_MB_INREG_JNT_CLSN_STS_1_H,
    ZUC_MB_INREG_JNT_CLSN_STS_1_L,
    ZUC_MB_INREG_JNT_CLSN_STS_2_H,
    ZUC_MB_INREG_JNT_CLSN_STS_2_L,
    ZUC_MB_INREG_JNT_CLSN_STS_3_H,
    ZUC_MB_INREG_JNT_CLSN_STS_3_L,
    ZUC_MB_INREG_JNT_CLSN_STS_4_H,
    ZUC_MB_INREG_JNT_CLSN_STS_4_L,
    ZUC_MB_INREG_JNT_CLSN_STS_5_H,
    ZUC_MB_INREG_JNT_CLSN_STS_5_L,
    ZUC_MB_INREG_JNT_CLSN_STS_6_H,
    ZUC_MB_INREG_JNT_CLSN_STS_6_L,

    ZUC_MB_INREG_TCP_POS_X_H,
    ZUC_MB_INREG_TCP_POS_X_L,
    ZUC_MB_INREG_TCP_POS_Y_H,
    ZUC_MB_INREG_TCP_POS_Y_L,
    ZUC_MB_INREG_TCP_POS_Z_H,
    ZUC_MB_INREG_TCP_POS_Z_L,
    ZUC_MB_INREG_TCP_POS_RX_H,
    ZUC_MB_INREG_TCP_POS_RX_L,
    ZUC_MB_INREG_TCP_POS_RY_H,
    ZUC_MB_INREG_TCP_POS_RY_L,
    ZUC_MB_INREG_TCP_POS_RZ_H,
    ZUC_MB_INREG_TCP_POS_RZ_L,
    ZUC_MB_INREG_TCP_SPD_X_H,
    ZUC_MB_INREG_TCP_SPD_X_L,
    ZUC_MB_INREG_TCP_SPD_Y_H,
    ZUC_MB_INREG_TCP_SPD_Y_L,
    ZUC_MB_INREG_TCP_SPD_Z_H,
    ZUC_MB_INREG_TCP_SPD_Z_L,
    ZUC_MB_INREG_TCP_SPD_RX_H,
    ZUC_MB_INREG_TCP_SPD_RX_L,
    ZUC_MB_INREG_TCP_SPD_RY_H,
    ZUC_MB_INREG_TCP_SPD_RY_L,
    ZUC_MB_INREG_TCP_SPD_RZ_H,
    ZUC_MB_INREG_TCP_SPD_RZ_L,
    ZUC_MB_INREG_TCP_SPD_H,
    ZUC_MB_INREG_TCP_SPD_L,
    ZUC_MB_INREG_FLOAT_1_H,
    ZUC_MB_INREG_FLOAT_1_L,
    ZUC_MB_INREG_FLOAT_2_H,
    ZUC_MB_INREG_FLOAT_2_L,
    ZUC_MB_INREG_FLOAT_3_H,
    ZUC_MB_INREG_FLOAT_3_L,
    ZUC_MB_INREG_FLOAT_4_H,
    ZUC_MB_INREG_FLOAT_4_L,
    ZUC_MB_INREG_FLOAT_5_H,
    ZUC_MB_INREG_FLOAT_5_L,
    ZUC_MB_INREG_FLOAT_6_H,
    ZUC_MB_INREG_FLOAT_6_L,
    ZUC_MB_INREG_FLOAT_7_H,
    ZUC_MB_INREG_FLOAT_7_L,
    ZUC_MB_INREG_FLOAT_8_H,
    ZUC_MB_INREG_FLOAT_8_L,
    ZUC_MB_INREG_L_INT_1_H,
    ZUC_MB_INREG_L_INT_1_L,
    ZUC_MB_INREG_L_INT_2_H,
    ZUC_MB_INREG_L_INT_2_L,
    ZUC_MB_INREG_L_INT_3_H,
    ZUC_MB_INREG_L_INT_3_L,
    ZUC_MB_INREG_L_INT_4_H,
    ZUC_MB_INREG_L_INT_4_L,
    ZUC_MB_INREG_L_INT_5_H,
    ZUC_MB_INREG_L_INT_5_L,
    ZUC_MB_INREG_L_INT_6_H,
    ZUC_MB_INREG_L_INT_6_L,
    ZUC_MB_INREG_L_INT_7_H,
    ZUC_MB_INREG_L_INT_7_L,
    ZUC_MB_INREG_L_INT_8_H,
    ZUC_MB_INREG_L_INT_8_L,

    ZUC_MB_INREG_ALL
} zuc_mb_input_reg_idx_t;

/* machine data */

typedef struct
{
    bool motors_servo_on;  /* RPI: servo on all the joint motors*/
    bool motion_enabled;   /* RPI: motion enable for all joints */
    bool robot_powered_on; /* RPI: robot power status */
    bool in_position;      /* RPI: all joints are in position */
    bool coord_mode;       /* RPA: TRUE if coord, FALSE if free */
    bool teleop_mode;      /* RPA: TRUE if teleop mode */
    bool teleop_tool_mode; /* RPA: TRUE if teleop_tool mode, by zxqi*/
    bool drag_mode;        /* RPA: Drag & teach flag*/
    bool coord_error;      /* RPA: TRUE if coord mode error */
    bool error_triggered;  /* RPA: TRUE if error triggered */
    bool on_soft_limit;    /* RPA: TRUE if outside a limit */
    bool next_to_limit;
    bool emergency_stop;   /* RPA: TRUE if any emergency stop triggered   */
    bool in_stop_mode;     /* RPA: TRUE if in stop mode */
    bool in_home_position; /* RPA: TRUE if in predefined home position*/

    bool zuc_enable_in;   /* power on request*/
    bool zuc_enable_cmd;  //本体上电指令
    // bool *ioaio_conn;          /* connection state of physical io module*/

    int32_t program_line; /* RPA: program line causing current motion */
    int32_t motion_type;  /* RPA: type (feed/rapid) of currently commanded motion */
    float current_vel;    /* RPI: velocity magnitude in machine units */
    float requested_vel;  /* RPI: requested velocity magnitude in machine units */
    float distance_to_go; /* RPI: distance to go in current move*/

    // virtual modbus IO, shared for all cabs
    bool mdbus_di[ZUCMOT_MAX_MODBUS_DIO];
    bool mdbus_do[ZUCMOT_MAX_MODBUS_DIO];
    float mdbus_ai[ZUCMOT_MAX_MODBUS_AIO];
    float mdbus_ao[ZUCMOT_MAX_MODBUS_AIO];

    // for physical IO, reused for all cabs
    bool physical_di[32];  /* RPI array: max physical pins for digital Inputs */
    bool physical_do[32];  /* RPI array: max physical pins for digital Outputs */
    float physical_ai[16]; /* RPI array: max physical pins for analog Inputs */
    float physical_ao[16]; /* RPI array: max physical pins for analog Onputs */

    // for cab V2.1
    // bool   *scb_inner_di[32];          /* RPI array: max physical pins for digital Inputs */
    // bool   *scb_inner_do[32];          /* RPI array: max physical pins for digital Outputs */
    // float *scb_anachn_setting_in;     /* read reg: convert to int: 0~3 bits for channel 2, 4~7 bits for channel 1*/
    // float *scb_anachn_setting_out;    /* write reg: convert to int*/
    // float *scb_hse_speed;
    // float *scb_hse_turns;
    // float *scb_hse_angle;
    // float *stm32_comm_timeout;
    // float *robot_power;
    // float *pdu_temperature;
    // float *robot_current;
    // float *scb_major_ver;
    // float *scb_minor_ver;
    // float *scb_ver_extra;

    // for mini cab
    // float *scb_digchn_setting;         /* digital channel setting, bit 0 for dout, bit 1 for din*/
    // float *scb_br_start_vol;           /* breaking resistance starting voltage*/

    bool program_run_req;
    bool program_pause_req;
    bool program_resume_req;
    bool program_stop_req;
    bool power_on_req;
    bool power_off_req;
    bool servo_enable_req;
    bool bp_servo_enable_req;
    bool collision_program_pause_req;

    bool delay_enable_req;
    bool pro_autorun_req;

    bool servo_disable_req;
    bool percentage_mode_level1_req;
    bool percentage_mode_level2_req;
    bool reduce_mode_req;
    int32_t collision_lv0_req;
    int32_t collision_lv1_req;
    int32_t collision_lv2_req;
    int32_t collision_lv3_req;
    int32_t collision_lv4_req;
    int32_t collision_lv5_req;
    int32_t collision_lv7_req;
    bool stop_mode_req;
    bool safetyguard_req;
    bool program_stat_idle;  //
    bool program_stat_running;
    bool program_stat_paused;
    bool stepping_stat_running;
    bool robot_poweron;
    bool robot_enabled;
    bool robot_motion;
    bool robot_static;
    bool robot_boot;
    bool robot_emergency_stop;
    bool robot_in_percentage_mode_level1;
    bool robot_in_percentage_mode_level2;
    bool robot_sys_protective_stop;
    bool return_to_initial_position;  //
    bool clear_error_req;
    bool drag_mode_req;       // TIO Key: drag mode toggle request
    bool drag_mode_exit_req;  // funcdi: exit drag mode request
    bool drag_mode_entr_req;  // funcdi: entr drag mode request
    bool sys_shutdown;
    bool robot_drag_mode;
    bool robot_collision_mode;
    bool three_position_enabling;

    float traj_pos_out;      /* RPA: traj internals, for debugging */
    float traj_vel_out;      /* RPA: traj internals, for debugging */
    uint32_t traj_active_tc; /* RPA: traj internals, for debugging */

    // realtime overrun detection
    uint32_t last_period; /* pin: last period in clocks */
    float last_period_ns; /* pin: last period in nanoseconds */

    joint_hal_t joint[ZUCMOT_MAX_JOINTS]; /* data for each joint */
    axis_hal_t axis[ZUCMOT_MAX_AXIS];     /* data for each axis */

    float servoVersionH[6];
    float servoVersionL[6];

    float robotSerialNumH[6];
    float robotSerialNumL[6];

    float instVoltageH[6];
    float instVoltageL[6];

    float instTemperatureH[6];
    float instTemperatureL[6];

    float actualPositionH[6];
    float actualPositionL[6];

    float actualTorqueH[6];
    float actualTorqueL[6];

    float errorCodeH[6];
    float errorCodeL[6];

    float errorStateH[6];
    float errorStateL[6];

    float enableStateH[6];
    float enableStateL[6];

    float collisionStateH[6];
    float collisionStateL[6];

    float tool_offsetH[6];
    float tool_offsetL[6];

    float tcp_velocityH[6];
    float tcp_velocityL[6];

    float tcp_compound_velH;
    float tcp_compound_velL;

    int32_t motion_error_code;
} zucmot_hal_data_t;

#endif